package com.subaiqiao.yunshiyuan.entrance.ysy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subaiqiao.yunshiyuan.basis.service.impl.BasisServiceImpl;
import com.subaiqiao.yunshiyuan.entrance.ysy.service.VerificationCodeService;
import com.subaiqiao.yunshiyuan.entrance.ysy.pojo.VerificationCode;
import com.subaiqiao.yunshiyuan.entrance.ysy.mapper.VerificationCodeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 曹朝禹
 * @since 2022-05-13
 */
@Service
@Transactional
public class VerificationCodeServiceImpl extends BasisServiceImpl<VerificationCode, VerificationCodeMapper> implements VerificationCodeService {

    @Override
    public Integer FindVerificationCodeCount() {
        return baseMapper.FindVerificationCodeCount();
    }

    @Override
    public Integer FindSMSVerificationCodeCount() {
        return baseMapper.FindSMSVerificationCodeCount();
    }

    @Override
    public Integer FindEmailVerificationCodeCount() {
        return baseMapper.FindEmailVerificationCodeCount();
    }

    @Override
    public Integer FindVerificationYesterdayRegister() {
        return baseMapper.FindVerificationYesterdayRegister();
    }

    @Override
    public Boolean VerificationCodeJudgment(String vf_reception, String vf_operation, String vf_type, String ViefCode) {
        QueryWrapper<VerificationCode> wrapper = new QueryWrapper<>();
        wrapper.eq("vf_reception", vf_reception)
                .eq("vf_operation",vf_operation)
                .eq("vf_type",vf_type)
                .orderByDesc("create_datetime");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MINUTE,-3);
        Date beforeD = calendar.getTime();
        wrapper.gt("create_datetime",beforeD);
        List<VerificationCode> veifCode = list(wrapper);
        for (VerificationCode item:veifCode) {
            if(item.getVfCode().equals(ViefCode)){
                return true;
            }
        }
        return false;
    }

    @Override
    public Integer FindCount() {
        return null;
    }

    @Override
    public VerificationCodeMapper getMapper() {
        return null;
    }
}
